#!/bin/sh
#
FETCH=1

if [ -f ./common_funcs.sh ]; then
    . ./common_funcs.sh
else
    echo "Cannot function without common_funcs.sh!" && exit 3
fi

function inst_mkisofs() {
    local cdr_ver="cdrtools-beta"
    local cdr_url="ftp://ftp.berlios.de/pub/cdrecord/alpha/${cdr_ver}.tar.gz"

    if [ ${FETCH} -gt 0 ]; then
        if chk_cmd curl; then
            curl -C - -O ${cdr_url}
        elif chk_cmd wget; then
            wget ${cdr_url}
        else
            echo "You must have either curl or wget for this script for work!"
            exit 2
        fi

        bak_dir ${cdr_ver}

        mv ${cdr_ver}.tar.{gz,bz2} # deal with the gheyity of cdrtools

        tar -jxf ${cdr_ver}.tar.bz2 # && rm ${cdr_ver}.tar.gz
    fi

    if [ ! ${FETCH} -eq 2 ]; then
        (cd $(echo ${cdr_ver} | cut -d'-' -f1)-2.01.01 && make && sudo make install) || return 1
#       cd .. && sudo rm -d -R ${cdr_ver}*
    fi
}

case ${1} in
    fetch)
        FETCH=2
        ;;
    nofetch)
        FETCH=0
esac

inst_mkisofs || exit 1

#EOF
